#pragma once
#include <string>
#include <memory>
#include <mutex>
#include <map>
#include <vector>
#include "json.h"


class DigitalSignageItem;


typedef enum{
    DigitalSignageMachineState_Idle,
    DigitalSignageMachineState_Prepare,
    DigitalSignageMachineState_Playing,
    DigitalSignageMachineState_Stop,
}DigitalSignageMachineState;

class DigitalSignageManagerEx{
public:
    using DigitalSignageId = uint32_t;
    using Ptr = std::shared_ptr<DigitalSignageManagerEx>;
    static Ptr Instance();

    DigitalSignageManagerEx();
    ~DigitalSignageManagerEx();

    void RegistRPC();
    bool Init();
private:
    void loadConfig(const std::string& configFile);

    bool createDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool addDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool delDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool getDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool moveDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool playDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool stopDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool setDigitalSignage(const Json::Value& req_params, Json::Value& res_result, 
            std::string& errinfo, int& errorCode);

    bool waitFileComplete();

    void handleNew();

    void stopPlay();

    void startPlay();

    std::vector<std::shared_ptr<DigitalSignageItem>> m_items;
    DigitalSignageId m_digitalSignageId;
    DigitalSignageMachineState m_digitalSignageState;
    std::recursive_mutex m_mutex;
};
